package com.example.demo.controller;

import com.example.demo.model.User;
import com.example.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Controller
@ResponseBody
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("/selectAll")
    public List<User> selectAll(){
        return userService.selectAll();
    }
    @RequestMapping(value = "/insertUser",method = RequestMethod.POST)
    public void insertUser(){
        userService.insertUser();
    }

    @RequestMapping(value = "/selectUserById",method = RequestMethod.GET)
    public User selectUserById(@RequestParam("id") Integer id){

        return userService.selectUserById(id);
    }

    @RequestMapping(value = "/updateUserById",method = RequestMethod.GET)
    public void updateUserById( User user){
        System.out.println("进入后端");
        if(user == null ){
            System.out.println("用户为空");
        }
        userService.updateUserById(user);
        System.out.println("更新成功");
    }

    @RequestMapping(value = "/deleteUser",method = RequestMethod.GET)
    public String deleteUser(@RequestParam("id")Integer id){

        userService.deleteUser(id);

        return "删除成功";
    }
}
